package com.pudu.mydemo.act;

import android.animation.ObjectAnimator;
import android.content.Intent;
import android.graphics.Rect;
import android.media.Image;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.pudutech.pdrobot.R;

/**
 * Created by guiliu on 2016/7/16.
 */
public class WifiLoginActivity extends BaseHomeActivity {
    private TextView wifi_name;
    private   int heightDifference;
    private LinearLayout login_center;
    private int max_heightDifference = 0;
    private ImageView ok ,cancel;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }


    @Override
    protected int getLayoutId() {
        return R.layout.wifi_login;
    }

    @Override
    public void initView() {
        super.initView();
        wifi_name = (TextView) findViewById(R.id.wifi_name);
        login_center = (LinearLayout)findViewById(R.id.login_center);
        ok = (ImageView)findViewById(R.id.ok);
    }

    @Override
    protected void onResume() {
        super.onResume();
        Intent intent = getIntent();
        String the_wifi_name = intent.getStringExtra("wifi_name");
        Toast.makeText(WifiLoginActivity.this, "wifi_name:" + the_wifi_name, Toast.LENGTH_SHORT).show();
        wifi_name.setText(the_wifi_name);
        float transtionsY = login_center.getTranslationY();
        dosomething();

      // ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(login_center,"translationY", transtionsY,-heightDifference);
        /*ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(login_center,"translationY", transtionsY,-300);
        objectAnimator.setDuration(5000);
        objectAnimator.start();*/
        ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(WifiLoginActivity.this, SmailActivity.class);
                startActivity(intent);
            }
        });
    }




    void dosomething() {
        final RelativeLayout myLayout =
                (RelativeLayout) findViewById(R.id.root_view);
        myLayout.getViewTreeObserver().
                addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    /**
                     * the result is pixels
                     */
                    @Override
                    public void onGlobalLayout() {

                        Rect r = new Rect();
                        myLayout.getWindowVisibleDisplayFrame(r);

                        int screenHeight = myLayout.getRootView().getHeight();
                        heightDifference = screenHeight - (r.bottom - r.top);
                       // Log.e(Keyboard Size, Size:+heightDifference);
                        if(heightDifference > max_heightDifference)
                        max_heightDifference = heightDifference;
                        Toast.makeText(WifiLoginActivity.this, "heightDifference:" + heightDifference, Toast.LENGTH_SHORT).show();
                        //boolean visible = heightDiff > screenHeight / 3;
                    }
                });
    }



}
